package com.example.store.controller;

import com.example.store.common.JsonResult;
import com.example.store.entity.Product;
import com.example.store.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("products")
public class ProductController extends BaseController  {
    @Autowired
    private IProductService productService;
    @GetMapping("hot_list")
    public JsonResult<List<Product>> hotList() {

        List<Product> hotList = productService.findHotList();
        return new JsonResult<List<Product>>(OK, hotList);
    }
    @GetMapping("{id}/details")
    public JsonResult<Product> findById(@PathVariable("id") Integer id) {
        Product data = productService.findById(id);
        return new JsonResult<Product>(OK, data);
    }
}
